package com.htl.exampro.question.controller;

import com.htl.exampro.base.model.PageResult;
import com.htl.exampro.base.model.ServerResponse;
import com.htl.exampro.question.pojo.query.AnswerPageParam;
import com.htl.exampro.question.pojo.vo.AnswerDetailVO;
import com.htl.exampro.question.pojo.vo.AnswerVO;
import com.htl.exampro.question.service.AnswerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 答题表 前端控制器
 * </p>
 *
 * @author hehehe
 * @since 2025-05-25
 */
@Tag(name = "答题管理", description = "答题相关接口")
@RestController
@RequestMapping("/answer")
public class AnswerController {

    @Autowired
    private AnswerService AnswerService;

    @Operation(summary = "查询答题", description = "根据主键查询答题信息")
    @GetMapping("/v1/queryAnswerById")
    public ServerResponse<AnswerVO> queryAnswerById(@RequestParam("AnswerId") String answerId) {
        AnswerVO AnswerVO = AnswerService.queryAnswerById(answerId);
        return ServerResponse.success(AnswerVO);
    }

    @Operation(summary = "分页查询答题", description = "支持按条件分页查询答题列表")
    @PostMapping("/v1/queryAnswerPage")
    public ServerResponse<PageResult<AnswerVO>> queryAnswerPage(@Validated @RequestBody AnswerPageParam pageParam) {
        PageResult<AnswerVO> pageResult = AnswerService.queryAnswerPage(pageParam);
        return ServerResponse.success(pageResult);
    }
    @Operation(summary = "查询答题详情", description = "支持按条件查询答题详情")
    @PostMapping("/v1/queryAnswerDetail")
    public ServerResponse<List<AnswerDetailVO>> queryAnswerDetail(@Validated @RequestBody AnswerPageParam pageParam) {
        List<AnswerDetailVO> answerDetailVOS = AnswerService.queryAnswerDetail(pageParam);
        return ServerResponse.success(answerDetailVOS);
    }

    @Operation(summary = "保存答题", description = "保存答题")
    @PostMapping("/v1/saveAnswer")
    public ServerResponse<Integer> saveAnswer(@Validated @RequestBody AnswerVO answerVO) {
        int i = AnswerService.saveAnswer(answerVO);
        return ServerResponse.success(i);
    }

    @Operation(summary = "保存全部答题", description = "保存全部答题")
    @PostMapping("/v1/saveAllAnswer")
    public ServerResponse<Void> saveAllAnswer(@Validated @RequestBody List<AnswerVO> answerVOS) {
        AnswerService.saveAllAnswer(answerVOS);
        return ServerResponse.success();
    }
}
